import javax.swing.*;
import java.awt.event.*;
import java.io.File;

final class FindItem extends AbstractAction{
    private final Doer frame;
    FindItem(String name,Doer frame){
    super(name);
    this.frame=frame;
    String iconFileName="images"+File.separator+name+".gif";
    if(new File(iconFileName).exists())putValue(SMALL_ICON,new ImageIcon(iconFileName));
  }
    public void actionPerformed(ActionEvent e){
      String word=JOptionPane.showInputDialog("Input the word you want to find!");

      if(word==null) JOptionPane.showMessageDialog(frame,"Can't find the word");
      else{
        InterWindow interWindow=(InterWindow)(frame.getTab().getComponentAt(frame.getSelect()));
        JTextArea textArea=interWindow.getTextArea();
        String text=textArea.getText();

	int index=text.indexOf(word);

	if(index<0) JOptionPane.showMessageDialog(null,"The word is not in the file");
	else{
          textArea.requestFocus();
          textArea.select(index,index+word.length());
	  frame.setWord(word);
	}
      }
    }
  }
